home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 98 / Skunkware 98.iso / src / net / bind-contrib.tar.gz / bind-contrib.tar / contrib / getkeyby / getkeyby.h < prev    next >
C/C++ Source or Header  |  1996-10-25  |  6KB  |  163 lines

  1. /*
  2.  * Get public keys from the Domain Name System.
  3.  * John Gilmore, 14 June 1996.
  4.  *
  5.  * This file is designed to be used in applications, until the Domain
  6.  * Name System on all hosts platforms of interest has been updated to
  7.  * include these definitions.  Include it after <resolv.h> and
  8.  * <arpa/nameser.h>.
  9.  *
  10.  * In the DNS implementation itself, all the definitions in this file
  11.  * are already in <resolv.h> and <arpa/nameser.h>.
  12.  */
  13.  
  14. /*
  15.  * Copyright (c) 1996 by Internet Software Consortium.
  16.  *
  17.  * Permission to use, copy, modify, and distribute this software for any
  18.  * purpose with or without fee is hereby granted, provided that the above
  19.  * copyright notice and this permission notice appear in all copies.
  20.  *
  21.  * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
  22.  * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
  23.  * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
  24.  * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
  25.  * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
  26.  * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
  27.  * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  28.  * SOFTWARE.
  29.  */
  30.  
  31. #if defined(LIBC_SCCS) && !defined(lint)
  32. static const char rcsid[] = "$Id: getkeyby.h,v 1.1 1996/10/25 17:06:14 vixie Exp $";
  33. #endif
  34.  
  35. /* First a little ANSI-ism */
  36. #ifndef __P
  37. #ifdef __STDC__
  38. #define    __P(x) x
  39. #else
  40. #define    __P(x) ()
  41. #ifndef const
  42. #define const /*nothing*/
  43. #endif /* const */
  44. #endif /* STDC */
  45. #endif /* __P */
  46.  
  47. /* Things missing from old versions of <arpa/nameser.h> */
  48. #ifndef HFIXEDSZ
  49. #define    HFIXEDSZ 12
  50. #endif
  51. #ifndef INT16SZ
  52. #define    INT16SZ 2
  53. #endif
  54. #ifndef INT32SZ
  55. #define    INT32SZ 4
  56. #endif
  57.  
  58. #ifndef T_KEY            /* When used with old nameser.h */
  59. #define    T_KEY        25        /* security key */
  60. #endif
  61.  
  62. #ifndef KEYFLAG_IPSEC            /* More old nameser.h support */
  63. /*
  64.  * Flags field of the KEY RR rdata
  65.  */
  66. #define    KEYFLAG_TYPEMASK    0xC000    /* Mask for "type" bits */
  67. #define    KEYFLAG_TYPE_AUTH_CONF    0x0000    /* Key usable for both */
  68. #define    KEYFLAG_TYPE_CONF_ONLY    0x8000    /* Key usable for confidentiality */
  69. #define    KEYFLAG_TYPE_AUTH_ONLY    0x4000    /* Key usable for authentication */
  70. #define    KEYFLAG_TYPE_NO_KEY    0xC000    /* No key usable for either; no key */
  71. /* The type bits can also be interpreted independently, as single bits: */
  72. #define    KEYFLAG_NO_AUTH        0x8000    /* Key not usable for authentication */
  73. #define    KEYFLAG_NO_CONF        0x4000    /* Key not usable for confidentiality */
  74.  
  75. #define    KEYFLAG_EXPERIMENTAL    0x2000    /* Security is *mandatory* if bit=0 */
  76. #define    KEYFLAG_RESERVED3    0x1000  /* reserved - must be zero */
  77. #define    KEYFLAG_RESERVED4    0x0800  /* reserved - must be zero */
  78. #define    KEYFLAG_USERACCOUNT    0x0400    /* key is assoc. with a user acct */
  79. #define    KEYFLAG_ENTITY        0x0200    /* key is assoc. with entity eg host */
  80. #define    KEYFLAG_ZONEKEY        0x0100    /* key is zone key for the zone named */
  81. #define    KEYFLAG_IPSEC        0x0080  /* key is for IPSEC use (host or user)*/
  82. #define    KEYFLAG_EMAIL        0x0040  /* key is for email (MIME security) */
  83. #define    KEYFLAG_RESERVED10    0x0020  /* reserved - must be zero */
  84. #define    KEYFLAG_RESERVED11    0x0010  /* reserved - must be zero */
  85. #define    KEYFLAG_SIGNATORYMASK    0x000F    /* key can sign DNS RR's of same name */
  86.  
  87. #define  KEYFLAG_RESERVED_BITMASK ( KEYFLAG_RESERVED3 | \
  88.                     KEYFLAG_RESERVED4 | \
  89.                     KEYFLAG_RESERVED10| KEYFLAG_RESERVED11) 
  90.  
  91. /* The Algorithm field of the KEY and SIG RR's is an integer, {1..254} */
  92. #define    ALGORITHM_MD5RSA    1    /* MD5 with RSA */
  93. #define    ALGORITHM_EXPIRE_ONLY    253    /* No alg, no security */
  94. #define    ALGORITHM_PRIVATE_OID    254    /* Key begins with OID indicating alg */
  95.  
  96. /* Signatures */
  97.                     /* Size of a mod or exp in bits */
  98. #define    MIN_MD5RSA_KEY_PART_BITS     512
  99. #define    MAX_MD5RSA_KEY_PART_BITS    2552
  100.                     /* Total of binary mod and exp, bytes */
  101. #define    MAX_MD5RSA_KEY_BYTES        ((MAX_MD5RSA_KEY_PART_BITS+7/8)*2+3)
  102.                     /* Max length of text sig block */
  103. #define    MAX_KEY_BASE64            (((MAX_MD5RSA_KEY_BYTES+2)/3)*4)
  104. #endif
  105. /* End of definitions for old nameser.h support.  */
  106.  
  107.  
  108.  
  109. #ifndef DNSKEY_NO_OPTIONS        /* Until these are in nameser.h
  110.                        and resolv.h. */
  111.  
  112. /* Representation of a key from the Domain Name System.  */
  113. struct dnskey {
  114.     char          *dname;        /* Domain name involved */
  115.     u_long           ttl;        /* Time to live (key validity period) */
  116.     unsigned      keyflags;        /* Flag bits */
  117.     u_char        protocol;        /* Network protocol this key is for */
  118.     u_char        algorithm;    /* Crypto algorithm this key is for */
  119.     u_char        keylen;        /* Length of key in key space */
  120.     u_char        *key;        /* The key itself */
  121. };
  122.  
  123. int    getkeybyname __P ((struct dnskey *, unsigned, unsigned));
  124.  
  125. /* Options for getkeybyname() */
  126. #define    DNSKEY_NO_OPTIONS        0    /* No options */
  127. #define    DNSKEY_AUTHORITATIVE_OPTION    0x0001    /* Require authoritative data */
  128. #define    DNSKEY_CRYPTOVALID_OPTION    0x0002    /* Require cryptovalid data */
  129.  
  130.  
  131.  
  132. /* A representation of a DNS resource record. */
  133. struct dns_rr {
  134.     char    *name;            /* Name of this RR, e.g. "toad.com" */
  135.     unsigned    type;        /* RR type e.g. T_A, T_CNAME, T_SOA */
  136.     unsigned    class;        /* RR class, effectively always IN */
  137.     u_long    ttl;            /* RR's remaining Time To Live */
  138.     unsigned    rdlength;    /* Length in bytes of RR data field */
  139.     u_char     *rdata;            /* The RR data field */
  140.     struct    dns_response *response;    /* Whole response containing this RR */
  141. };
  142. typedef struct dns_rr dns_rr;
  143.  
  144. /* A representation of the answer that the DNS sends back to a resolver. */
  145. struct dns_response {
  146.     void    *msg, *eom;    /* Args for dn_expand of rdata's */
  147.     /* The query FIXME-not here yet */
  148.     char    *queryname;    /* Name used in query e.g. "toad.com" */
  149.     unsigned    ans_count;
  150.     struct    dns_rr *answers;
  151.     unsigned    auth_count;
  152.     struct    dns_rr *authorities;
  153.     unsigned    glue_count;
  154.     struct    dns_rr *glue;
  155. };
  156.  
  157. #define    res_parse_response __res_parse_response
  158.  
  159. struct dns_response *
  160.         res_parse_response __P((const unsigned char *, int));
  161.  
  162. #endif /* DNSKEY_NO_OPTIONS */
  163.